package app.netant.galgame.yuinya.net;

import cn.lily.com.db.sql.manager.DBOfflineManager;
import cn.lily.com.lang.number.MathUtil;

/**
 * 基本操作实体类
 * @author JiaJ
 * @date 2018年6月26日
 *
 */
public class YuiNyaNetEntity {
	
	private String gameID = System.currentTimeMillis()+MathUtil.random(3);
	
	private String gameName = "";
	
	private String gameHref = "";
	
	private String gamePro = "";
	
	private String gameType = "";
	
	private String gameDate = "";
	
	private String getchuUrl = "";
	
	private String standUrl = "";
	
	private String gameMemo = "";
	
	private String gameThunder = "";
	
	private String fileName = "";
	
	private String filePwd = "";
	
	private String fileUrl = "";
	
	protected String getString(String src){
		return src.replaceAll("'", "’")
				  .replaceAll("\"", "”")
				  .replaceAll("&nbsp;", "")
				  .replaceAll("<br>", "")
				  .replaceAll("<br/>", "")
				  .replaceAll("<p>", "")
				  .replaceAll("</p>", "");
	}

	public void setGameID(String gameID) {
		this.gameID = gameID;
	}

	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	public void setGameHref(String gameHref) {
		this.gameHref = gameHref;
	}

	public void setGamePro(String gamePro) {
		this.gamePro = gamePro;
	}

	public void setGameType(String gameType) {
		this.gameType = gameType;
	}

	public void setGameDate(String gameDate) {
		this.gameDate = gameDate;
	}

	public void setGetchuUrl(String getchuUrl) {
		this.getchuUrl = getchuUrl;
	}

	public void setStandUrl(String standUrl) {
		this.standUrl = standUrl;
	}

	public void setGameMemo(String gameMemo) {
		this.gameMemo = gameMemo;
	}

	public void setGameThunder(String gameThunder) {
		this.gameThunder = gameThunder;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void setFilePwd(String filePwd) {
		this.filePwd = filePwd;
	}

	public void setFileUrl(String fileUrl) {
		this.fileUrl = fileUrl;
	}
	
	public void setTags(String tagName,String tagValue){
		
		tagName = tagName.trim().toUpperCase();
		tagValue = this.getString(tagValue.trim());
		
		if("游戏名称".equals(tagName)){
			this.gameName = tagValue;
		}
		
		else if("游戏厂商".equals(tagName)){
			this.gamePro = tagValue;
		}

		else if("游戏类型".equals(tagName)){
			this.gameType = tagValue;
		}

		else if("发售日期".equals(tagName)){
			this.gameDate = tagValue;
		}
		
		else if("GETCHU介绍页".equals(tagName)){
			this.getchuUrl = tagValue;
		}
		
		else if("原公司介绍页".equals(tagName)){
			this.standUrl = tagValue;
		}
		
	}
	
	public void insert(){
		
		try {
			
			String insertSQL = "insert into ${schema}.LEO_YUINYA_GAL_INFO "
					                + "(GAME_ID,GAME_HREF,GAME_NAME,GAME_PRO,GAME_TYP,"
					                + "GAME_DATE,GETCHU_URL,STAND_URL,GAME_MEMO,GAME_THUNDER,"
					                + "GAME_FILE_NAM,GAME_FILE_PWD,GAME_YUN_URLS) "
					                + "values "
					                + "('"+this.gameID+"','"+this.gameHref+"','"+this.gameName+"','"+this.gamePro+"','"+this.gameType+"',"
					               + "'"+this.gameDate+"','"+this.getchuUrl+"','"+this.standUrl+"','"+this.gameMemo+"','"+this.gameThunder+"',"
					               + "'"+this.fileName+"','"+this.filePwd+"','"+this.fileUrl+"')";
			
			DBOfflineManager.getDBManager().executeUpdate(insertSQL);
			
		} catch (Exception e) {
			e.printStackTrace();		
			DBOfflineManager.getDBManager().executeUpdate("insert into ${schema}.LEO_YUINYA_EXCEP (EXCEP_ID,EXCEP_URL,EXCEP_LEVEL) "
					+ "values ('"+System.currentTimeMillis()+MathUtil.random(3)+"','"+this.gameHref+"','2') ");
		}
		
	}
	
}
